﻿using System;
using System.CodeDom.Compiler;

namespace FBGraph.ClientGenerator.CodeGen
{
    public class Constructor : Member
    {
        public Constructor(CodeGenType container, params Parameter[] parameters)
        {
            this.Container = container;
            this.Accessibility = "public";
            this.Parameters = new ParameterList(parameters);
        }

        public ParameterList Parameters { get; private set; }
        public String Accessibility { get; set; }
        public CodeGenType Container { get; private set; }
        public String Body { get; set; }
        public ChainedConstructor ChainedConstructor { get; set; }

        protected override void WriteDeclaration(CodeGenWriter writer)
        {
            if (!String.IsNullOrEmpty(this.Accessibility))
            {
                writer.Write(this.Accessibility);
                writer.Write(' ');
            }

            writer.Write(this.Container.Name);
            writer.Write("(");
            writer.Write(this.Parameters);
            writer.Write(")");

            if (this.ChainedConstructor != null) writer.Write(this.ChainedConstructor);

            writer.WriteLine();
        }

        protected override void WriteBody(CodeGenWriter writer)
        {
            if (this.Body != null) writer.WriteLine(this.Body);
        }
    }
}